<?php
    include 'include/admin_function.php';
    valid_admin();
	$errorMsg = '';
	if (empty($_POST['title']))
		$errorMsg = 'title cannot be NULL';
	else if (empty($_POST['start']))
		$errorMsg = 'start time cannot be NULL';
	else if (empty($_POST['end']))
		$errorMsg = 'end time cannot be NULL';
	else if (empty($_POST['p0']))
		$errorMsg = 'problem cannot be NULL';

	if (!empty($errorMsg)){
		echo $errorMsg;
		exit;
	}

    $title = $_POST['title'];
    $start_time = $_POST['start'];
    $end_time = $_POST['end'];
    for ($i = 0; $i < 26; $i++){
		if (empty($_POST['p' . $i])) break;
        else {
            $problem[$i]['uva_problem_id'] = $_POST['p' . $i];
            $problem[$i]['url'] = "http://acmicpc-live-archive.uva.es/nuevoportal/data/problem.php?p=" . $_POST['p' . $i];
            $problem[$i]['title'] = get_problem_title($problem[$i]['url']);
        }
	}
    if (add_contest($title, $start_time, $end_time, $problem))
        header("location:index");
?>
